#include<iostream>
using namespace std;
const int N = 1e5 + 10;
int n;
int f[N];
int arr[N];
void fun()
{
	f[0] = 0;
	f[1] = 1;
	for (int i = 2; i < N; i++) {
		if (i % 2 == 0) {
			f[i] = f[i / 2];
		}
		else {
			f[i] = f[i / 2] + f[(i / 2) + 1];
		}
	}
}
void fun1()
{
	int ma = -10;
	for (int i = 1; i < N; i++) {
		ma = max(ma, f[i]);
		arr[i] = ma;
	}
}
int main()
{
	fun();
	fun1();
	while (cin >> n) {
		//cout << f[10] << endl;
		if (n == 0) {
			break;
		}
		cout << arr[n] << endl;
	}
	return 0;
}